package com.example.demo.service;

import com.example.demo.entry.Organization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.stereotype.Service;

import static org.springframework.ldap.query.LdapQueryBuilder.query;

/**
 * @author yzd
 */
@Service
public class LdapOrganizationService {

    @Autowired
    private LdapTemplate ldapTemplate;

    /**
     * 创建
     *
     * @param organization
     * @return
     */
    public Organization create(Organization organization) {
        ldapTemplate.create(organization);
        return organization;
    }

    /**
     * 查询
     * @param ou
     * @return
     */
    public Organization findByCn(String ou) {
        return ldapTemplate.findOne(query().where("ou").is(ou), Organization.class);
    }

    /**
     * 更新
     * @param organization
     * @return
     */
    public Organization modifyOrganization(Organization organization) {
        ldapTemplate.update(organization);
        return organization;
    }

    /**
     * 更新
     * @param organization
     */
    public void deleteOrganization(Organization organization) {
        ldapTemplate.delete(organization);
    }

}
